package com.ec.edu.exception;

import lombok.Data;

/**
 * @Author: jxyang
 * @Date: 2018/11/14 11:23
 * @Description:
 */
@Data
public class CommonException extends RuntimeException
{
    Integer DEFAULT_ERROR_CODE = -1;

    private Integer code;
    private String errorMessage;

    public CommonException(String errorMessage) {
        super(errorMessage);
        this.code = DEFAULT_ERROR_CODE;
        this.errorMessage = errorMessage;
    }

    public CommonException(Integer code, String errorMessage) {
        super(errorMessage);
        this.code = code;
        this.errorMessage = errorMessage;
    }

    public CommonException(Integer code, String errorMessage, Object... arguments) {
        super(errorMessage);
        for (Object argument : arguments) {
            errorMessage = errorMessage.replaceFirst("\\{}", argument.toString());
        }
        this.code = code;
        this.errorMessage = errorMessage;
    }
}
